<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@page import="com.lmpop.trade.ti_discountpolicy.*" %>
<%@page import="java.util.*" %>
<%@page import="com.lmpop.trade.ts_custclass.*" %>
<%@page import="com.lmpop.trade.ti_gift.Ti_giftInfo"%>
<%@page import="com.lmpop.trade.ti_voucher.*" %>
<%@page import="com.lmpop.trade.ts_category.Ts_categoryInfo"%>
<html>
  <head>
    
    <title>修改优惠策略设置</title>
	<link href="/program/admin/index/css/style.css" rel="stylesheet" type="text/css">
	<script type="text/javascript" src="index.js"></script>
	<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/engine.js'></script>
	<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/util.js'></script>
	<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/interface/Ti_PaymentRulesInfo.js'></script>
	<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/interface/Ti_discountpolicyInfo.js'></script>  
	<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/interface/Ti_giftInfo.js'></script>
	<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/interface/Ts_categoryInfo.js'></script> 
	<script type="text/javascript" src="/program/admin/goods/s_classify.js"></script>
	<script language="javascript" type="text/javascript" src="/program/plugins/calendar/WdatePicker.js"></script>
</head>

<body>

  <% 
  
  	String sessionuser_id="";
 	if(session.getAttribute("session_user_id")!=null){
	     sessionuser_id  =session.getAttribute("session_user_id").toString();
	}
  	String discount_id="";
  	if(request.getParameter("discount_id")!=null) discount_id = request.getParameter("discount_id");
  	Ti_discountpolicyInfo ti_discountpolicyInfo = new Ti_discountpolicyInfo();
  	List list = ti_discountpolicyInfo.getListByPk(discount_id);
  	Hashtable map = new Hashtable();
  	if(list!=null && list.size()>0) map = (Hashtable)list.get(0);
  	
  	String good_offer="",class_attr="",member_level="",offer_type="",spending="",number="",discount="",ship_offer="",voucher_type="",voucher_num="",send_a_few="",gift_ids="",order_amount="",start_time="",end_time="",rsrv_str1="",rsrv_str2="",rsrv_str3="",in_date="",user_id="";
  	if(map.get("member_level")!=null) member_level = map.get("member_level").toString();
  	if(map.get("class_attr")!=null) class_attr = map.get("class_attr").toString();
  	if(map.get("offer_type")!=null) offer_type = map.get("offer_type").toString();
  	if(map.get("spending")!=null) spending = map.get("spending").toString();
  	if(map.get("number")!=null) number = map.get("number").toString();
  	if(map.get("discount")!=null) discount = map.get("discount").toString();
  	if(map.get("ship_offer")!=null) ship_offer = map.get("ship_offer").toString();
  	if(map.get("voucher_type")!=null) voucher_type = map.get("voucher_type").toString();
  	if(map.get("voucher_num")!=null) voucher_num = map.get("voucher_num").toString();
  	if(map.get("send_a_few")!=null) send_a_few = map.get("send_a_few").toString();
  	if(map.get("gift_ids")!=null) gift_ids = map.get("gift_ids").toString();
  	if(map.get("order_amount")!=null) order_amount = map.get("order_amount").toString();
  	if(map.get("start_time")!=null) start_time = map.get("start_time").toString();
  	if(map.get("end_time")!=null) end_time = map.get("end_time").toString();
  	if(start_time.length()>10)start_time=start_time.substring(0,10);
  	if(end_time.length()>10)end_time=end_time.substring(0,10);
  	if(map.get("in_date")!=null) in_date = map.get("in_date").toString();
  	if(map.get("user_id")!=null) user_id = map.get("user_id").toString();
  	if(map.get("good_offer")!=null) good_offer = map.get("good_offer").toString();
  	Map custclassinfoMap = new Hashtable();
	custclassinfoMap.put("class_type","1");
	Ts_custclassInfo custclassinfo = new Ts_custclassInfo();
	String custclass_select =  custclassinfo.getSelectString(custclassinfoMap,"");
	String class_name=custclassinfo.getcust_class_name(member_level);
	
	Ti_giftInfo giftInfo=new Ti_giftInfo();
	Map giftmaps=giftInfo.getGiftnames();
	Ti_PaymentRulesInfo ti_paymentruleInfo =new Ti_PaymentRulesInfo();
	
	String rules_select=ti_paymentruleInfo.getSelectString("");
	
	 String catAttr[] = class_attr.split("\\|");
  String cat_names ="";  
  if(!class_attr.equals(""))
  {
      String catIds[] =	class_attr.split("\\|");	
       Ts_categoryInfo ts_categoryInfo = new Ts_categoryInfo();
       Map catMap = ts_categoryInfo.getCatClassMap("2");
      for(String catId:catIds)
      {
         if(catMap!=null)
         {
             if(catMap.get(catId)!=null)
             {
              cat_names +=catMap.get(catId).toString()+"  ";                 
             }                  
         
         }                 
      }		    
	 }
	
  %>
	
	<h1>修改优惠策略设置</h1>
	
	<form action="/doTradeReg.do" method="post" name="updateForm">

	<table width="100%" cellpadding="0" cellspacing="1" border="0" class="listtab">
	
		
		<tr>
			<td align="right" width="30%">
				优惠类型<font color="red">*</font>
			</td>
			<td>
				<select name="offer_type" id="offer_type" onchange="setOffer_type(this.value)" >
								  <option value="1" <%if(offer_type.equals("1")){ %>selected="selected"<%} %>>购物送礼</option>
								  <option value="2" <%if(offer_type.equals("2")){ %>selected="selected"<%} %>>满额打折</option>
								  <option value="3" <%if(offer_type.equals("3")){ %>selected="selected"<%} %>>满量打折</option>
								  <option value="4" <%if(offer_type.equals("4")){ %>selected="selected"<%} %>>运费优惠</option>
								  <option value="5" <%if(offer_type.equals("5")){ %>selected="selected"<%} %>>满额赠送</option>
								  <option value="6" <%if(offer_type.equals("6")){ %>selected="selected"<%} %>>买几送几</option>
				</select>
		</tr>
		
		<tr id="tr0" >
			<td align="right" width="30%">
				会员类型<font color="red">*</font>
			</td>
			<td>
				<select name="member_level" id="member_level" onclick="setMember_level()" >
									<option value="">请选择</option>
									<option value="<%=member_level %>" selected="selected"><%=class_name %></option>
								  	<%=custclass_select%>
				</select>
		</tr>
		
		<tr id="tr1" >
			<td align="right" width="30%">
				额满
			</td>
			<td><input name="spending" id="spending" value="<%if(spending.equals("0.00")) %><%="" %><%else %><%=spending %>" size="5" maxlength="5" type="text" onKeyUp="if(isNaN(value))this.value='';clearStr(0)"/></td>
		</tr>
		
		<tr id="tr2" >
			<td align="right" width="30%">
				量满
			</td>
			<td><input name="number" id="number" value="<%if(number.equals("0")) %><%="" %><%else %><%=number %>" size="5" maxlength="5" type="text" onKeyUp="if(isNaN(value))this.value='';clearStr(1)"/></td>
		</tr>
		
		<tr id="tr3" >
			<td align="right" width="30%">
				打折率
			</td>
			<td><input name="discount" id="discount" value="<%if(discount.equals("0")) %><%="" %><%else %><%=discount %>" size="5" maxlength="5" type="text" onKeyUp="if(isNaN(value))this.value=''"/>%</td>
		</tr>
		
		<tr id="tr4" >
			<td align="right" width="30%">
				运费优惠
			</td>
			<td><input name="ship_offer" id="ship_offer" value="<%if(ship_offer.equals("0.00")) %><%="" %><%else %><%=ship_offer %>" size="5" maxlength="5" type="text" onKeyUp="if(isNaN(value))this.value='';clearStr(3)"/>元</td>
		</tr>
		
		<tr id="tr5" >
			<td align="right" width="30%">
				送几个
			</td>
			<td><input name="send_a_few" id="send_a_few" value="<%if(send_a_few.equals("0.00")) %><%="" %><%else %><%=send_a_few %>" size="5" maxlength="5" type="text" onKeyUp="if(isNaN(value))this.value='';clearStr(6);"/></td>
		</tr>
		
		<tr>
			<td align="right" width="30%">
				优惠券类型
			</td>
			<td>
				<select name="voucher_type" id="voucher_type" onclick="setVoucher_type(this.value)" >
								<option value="">请选择</option>
								<%=rules_select %>
				</select>
			</td>
		</tr>
		
		<tr>
			<td align="right" width="30%">
				优惠券数量
			</td>
			<td><input name="voucher_num" id="voucher_num" value="<%if(voucher_num.equals("0")) %><%="" %><%else %><%=voucher_num %>" size="5" maxlength="5" type="text" readonly="readonly"/></td>
		</tr>
		
		
		<tr id="tr6" >
			<td align="right" width="20%">
				礼品分类：
			</td>
			<td>
				<%=cat_names %>&nbsp;
			   <input type="button" class="buttoncss" name="" value="修改"
								onclick="showDiv(1)" />
							</p>
				<div id="cat_div" style="display: none;">
					 <select name="sort1" id="sort1" onclick="setSecondClass(this.value);" >
								  <option value="">请选择</option>
					</select>	
					<select name="sort2" id="sort2" onclick="setTherdClass(this.value);">
								  <option value="">请选择</option>
					</select>	
					<select name="sort3" id="sort3" >
								  <option value="">请选择</option>
					</select>
			</td>
		</tr>
		
		<tr id="tr7" >
			<td align="right" width="30%">
				礼品选择
			</td>
			<td>
				<input type="hidden" id="gift_id" value="<%=gift_ids %>"/>
				<select name="gift_ids" id="gift_ids" onclick="setGifts(this.value);">
								  <option value="">请选择</option>
				</select>
			</td>
		</tr>
		<tr>
			<td align="right" width="30%">
				订单数量<font color="red">*</font>
			</td>
			<td>
				<%
					if(order_amount.equals("1")){%>
						<input  id="order_amount1" type="radio" name="order_amount" value="1"  checked="checked" onclick="clearOrder(2)"/>单个
						<input type="radio" id="order_amount2" name="order_amount" value="0" onclick="clearOrder(3)"/>多个
					<%}else if(order_amount.equals("0")){%>
						<input  id="order_amount1" type="radio" name="order_amount" value="1" onclick="clearOrder(2)"/>单个
						<input type="radio" id="order_amount2" name="order_amount" value="0" checked="checked" onclick="clearOrder(3)"/>多个
					<%}else {%>
						<input  id="order_amount1" type="radio" name="order_amount" value="1" onclick="clearOrder(2)"/>单个
						<input type="radio" id="order_amount2" name="order_amount" value="0" onclick="clearOrder(3)"/>多个
				<%} %>				
			</td>
		</tr>
			<tr>
			<td align="right" width="30%">
				商品优惠
			</td>
			<td>
				<%
					if(good_offer.equals("1")){%>
						<input  id="good_offer1" name="good_offer" type="radio" value="1" checked="checked" onclick="clearOrder(1)"/>是
						<input  id="good_offer2" name="good_offer" type="radio" value="0" onclick="clearOrder(0)"/>否
					<%}else{%>
						<input  id="good_offer1" name="good_offer" type="radio" value="1" onclick="clearOrder(1)" />是
						<input  id="good_offer2" name="good_offer" type="radio" value="0" checked="checked" onclick="clearOrder(0)"/>否
				<%} %>
				
			</td>
		</tr>
		<tr>
			<td align="right" width="30%">
				开始时间<font color="red">*</font>
			</td>
			<td>
				<input name="start_time" id="start_time" size="20" value="<%=start_time %>" maxlength="20" type="text"
				 onfocus="WdatePicker({readOnly:true})" />
			</td>
		</tr>
		
		<tr>
			<td align="right" width="30%">
				结束时间<font color="red">*</font>
			</td>
			<td><input name="end_time" id="end_time" size="20" maxlength="20" value="<%=end_time %>" type="text" onfocus="WdatePicker({readOnly:true})" /></td>
		</tr>
		
	</table>
	
	<table width="100%" cellpadding="0" cellspacing="0" border="0">
		<tr>
			<td align="center">
				<input type="hidden" name="bpm_id" value="2875" />
				<input type="hidden" name="class_attr" id="class_attr" value="<%=class_attr %>" />
				<input name="order_amount" id="order_amount" value="<%=order_amount %>"  type="hidden" />
	  			<input type="hidden" name="discount_id" value="<%=discount_id %>" />
	  			<input type="hidden" name="user_id" value="<%=sessionuser_id %>" />
				<input type="button" class="buttoncss" name="tradeSub" value="提交" onclick="return checkSub('updateForm');"/>&nbsp;&nbsp;
				<input type="button" class="buttoncss" name="tradeRut" value="返回" onclick="window.location.href='index.jsp';"/>
			</td>
		</tr>
	</table>
	</form>
</body>
	<script type="text/javascript">
		var type=<%=offer_type%>;
		setOffer_type(type);
		setGifts("<%=gift_ids%>");
	</script>
</html>
